<?php

class BackSettingController extends BackController {

    static $model_name = 'setting';
    static $display_name = '设定';

    public function doUpdate($entry){
        $service = $this->getService();
        if($this->isSubmit()){
            if(!$service->updateSetting($entry)){
                return Redirect::action('BackSettingController@doUpdate', array($entry->id))->withInput()->with('errors',$this->service->errors());
            }else{
                return Redirect::action('BackSettingController@doUpdate', array($entry->id))->with('success','修改'.self::$display_name.'成功');
            }
        }

        return View::make(self::$view_path.'.'.self::$model_name.'.create_update', compact('entry', 'permissions'));
    }

    public function getService() {
        if(is_null($this->service)){
            $this->service = new BackSettingService();
        }
        return $this->service;
    }

}
